﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GraphicsTester
{
    public enum PropertyName
    {
        Test,
        Minor,
        Vitaminas,
        Testa,
        Bota,
        Perdigota
    }

    public class Property
    {
        public String GetName1
        {
            get
            {
                return "Vitaminas";
            }
            set
            {
                string str = value;
            }
        }

        string nameStr = "";
        
        public String GetName {
            get
            {
                return nameStr;
            }
            set
            {
                nameStr = value;
            }
        }

        public double quantity = 0;

        public double Quantity
        {
            get
            {
                return quantity;
            }
            set
            {
                quantity = Math.Round(value, 2);
            }
        }

        private string quantityStr;

        public string GetQuantity
        {
            get
            {
                return Quantity.ToString("F2");
            }
            set
            {
                quantityStr = value; 
            }
        }


        public Property(String name, double qt)
        {
            GetName = name;
            Quantity = qt;
        }
    }

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private List<Property> m_valueList = new List<Property>();

        private List<Property> m_obList = new List<Property>();

        private List<double> m_doubleList = new List<double>();

        

        private System.Collections.ObjectModel.Collection<System.Windows.Style> MakePalette(List<Property> list)
        {
            System.Collections.ObjectModel.Collection<System.Windows.Style> palette = new System.Collections.ObjectModel.Collection<System.Windows.Style>();
            Style style = new Style(typeof(Control));
            foreach (Property item in list)
            {
                SolidColorBrush brush = null;
                if (item.GetName == "Vitaminas")
                {
                    brush = new SolidColorBrush(Colors.Black);
                }
                else if (item.GetName == "Vitaminas1")
                {
                    brush = new SolidColorBrush(Colors.Red);
                }


                //switch (item.GetName)
                //{
                //    case PropertyName.Vitaminas: brush = new SolidColorBrush(Colors.Black); break;
                //    //case PropertyName.Minor: brush = new SolidColorBrush(Colors.Black); break;
                //    //case PropertyName.Test: brush = new SolidColorBrush(Colors.Black); break;
                //    //case PropertyName.Testa: brush = new SolidColorBrush(Colors.Black); break;
                //    //case PropertyName.Perdigota: brush = new SolidColorBrush(Colors.Black); break;
                //}
                style.Setters.Add(new Setter() { Property = Control.BackgroundProperty, Value = brush });
                palette.Add(style);
            }
            return palette;
        }


        public MainWindow()
        {
            InitializeComponent();

            PopulateChart();
        }

        /// <summary>
        /// Fill the chart with default values
        /// </summary>
        private void PopulateChart()
        {
            m_valueList.Add(new Property("Vitaminas", 50));
            //m_valueList.Add(new Property(PropertyName.Minor, 70));
            //m_valueList.Add(new Property(PropertyName.Test, 10));
            //m_valueList.Add(new Property(PropertyName.Testa, 60));
            //m_valueList.Add(new Property(PropertyName.Bota, 80));
            //m_valueList.Add(new Property(PropertyName.Perdigota, 50));
            columnSeries.DataContext = m_valueList;

            m_obList.Add(new Property("Vitaminas1", 40));
            //m_obList.Add(new Property(PropertyName.Minor, 40));
            //m_obList.Add(new Property(PropertyName.Test, 30));
            //m_obList.Add(new Property(PropertyName.Testa, 45));
            //m_obList.Add(new Property(PropertyName.Bota, 100));
            //m_obList.Add(new Property(PropertyName.Perdigota, 70));
            columnSeries2.DataContext = m_obList;

            List<Property> m_obList3 = new List<Property>(new Property[] {new Property("Vitaminas2", 260)});
            // m_obList3.Add();
            columnSeries3.DataContext = new List<Property>(new Property[] { new Property("Vitaminas2", 260) });  // m_obList3;

            List<Property> m_obList4 = new List<Property>();
            m_obList4.Add(new Property("Vitaminas3", 135));
            columnSeries4.DataContext = m_obList4;

            List<Property> m_obList5 = new List<Property>();
            m_obList5.Add(new Property("Vitaminas5", 170));
            columnSeries5.DataContext = m_obList5;

            List<Property> m_obList6 = new List<Property>();
            m_obList6.Add(new Property("Vitaminas6", 56));
            columnSeries6.Title = "Vitaminas " + 56 + "%";
            columnSeries6.DataContext = m_obList6;

            //lineSeries.DataContext = m_obList;

           // columnChart.StylePalette = MakePalette(m_valueList);
           columnChart.FontSize = 10;
        }

        /// <summary>
        /// Refresh chart values
        /// </summary>
        private void RefreshChart()
        {
            int i = 0;
            foreach (Property fp in m_valueList)
            {
                if (fp.GetName == "Vitaminas")
                {
                    fp.Quantity = m_doubleList[i];
                    columnSeries.Title = fp.GetName + "  " + fp.Quantity + "%";
                }
            }

            foreach (Property fp in m_obList)
            {
                if (fp.GetName == "Vitaminas1")
                {
                    fp.Quantity = m_doubleList[i+1];
                    columnSeries2.Title = fp.GetName + " " + fp.Quantity + "%";
                }
                //else if (fp.GetName == PropertyName.Test)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Testa)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Perdigota)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Bota)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                i++;
            }

            columnSeries.Refresh();
            columnSeries2.Refresh();
        }

        private void RefreshLineData()
        {
            int i = 0;
            foreach (Property fp in m_obList)
            {
                //if (fp.GetName == PropertyName.Vitaminas)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Minor)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Test)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Testa)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Perdigota)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                //else if (fp.GetName == PropertyName.Bota)
                //{
                //    fp.Quantity = m_doubleList[i];
                //}
                i++;
            }

            //lineSeries.Refresh();
        }


        /// <summary>
        /// Hanlde the event for adding a Food to list
        /// </summary>
        /// <param name="foodList">List(Food)</param>
        /// <param name="numDays">int</param>
        internal void AddFood(List<double> doubleList)
        {
            m_doubleList = doubleList;
            RefreshChart();
        }

        private void RefreshGraphData_Click(object sender, RoutedEventArgs e)
        {
            List<double> fakeData = new List<double>();

            Random r = new Random(DateTime.Now.TimeOfDay.Milliseconds);

            for (int i = 0; i < 6; i++ )
            {
                double d = r.NextDouble();
                fakeData.Add(d * 100);
                System.Console.WriteLine("Val: " + d);
            }

            AddFood(fakeData);
        }
    }
}
